package com.zline.foodraise.ui.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.app.FragmentActivity;
import android.util.TypedValue;
import android.view.Window;

import com.baidu.mobstat.StatService;
import com.zline.foodraise.R;
import com.zline.foodraise.constant.Constant;
import com.zline.foodraise.util.LUtil;
import com.zline.foodraise.view.dialog.LoadingProgressDialog;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.WindowFeature;

/**
 * Created by heshantao on 15/6/25.
 * 基础类
 */
@EActivity
@WindowFeature(Window.FEATURE_NO_TITLE)
public class ZlineActivity extends FragmentActivity {
    private static final String LOG_TAG = ZlineActivity.class.getSimpleName();
    LoadingProgressDialog loadDialog;
    final TypedValue mTypedValue = new TypedValue();

    BroadcastReceiver exitReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        goback();
    }

    /**
     * 返回键 时候的动画
     */
    public void goback() {
        finish();
    }


    //显示加载对话框
    public void showLoadingDialog() {
        loadDialog = LoadingProgressDialog.init(this);
        loadDialog.show();
    }

    //加载框消失
    public void dissLoadingDialog() {
        if (loadDialog != null) {
            if (loadDialog.isShowing()) {
                loadDialog.dismiss();
            }
        }
    }


    void registerBroadcast() {
        IntentFilter intentFileter = new IntentFilter();
        intentFileter.addAction(Constant.EXIT_ACTION);
        registerReceiver(exitReceiver, intentFileter);
    }

    public int getBackground(){
        int mBackground;
        this.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true);
        mBackground=mTypedValue.resourceId;
        return mBackground;
    }

    @Override
    protected void onResume() {
        super.onResume();
        registerBroadcast();
        //StatService.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //StatService.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(exitReceiver);
    }
}
